package logic

import (
	"context"
	"duo/cache"
	"math/rand"
	"time"

	"duo/duorpc/duorpc"
	"duo/duorpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *duorpc.SendSmsRequest) (*duorpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line
	code := rand.Intn(9000) + 1000

	//send, err := pkg.Send(in.Title, strconv.Itoa(code))
	//if err != nil {
	//	return nil, err
	//}
	//
	//if send.Code != 2 {
	//	return nil, errors.New(send.Msg)
	//}

	cache.Rdb.Set(l.ctx, "sendSmSCode"+in.Title, code, time.Minute*3)

	return &duorpc.SendSmsResponse{}, nil
}
